// Foundation.cpp: implementation of the CFoundation class.
//
//////////////////////////////////////////////////////////////////////

#include "iface.h"
#include "Foundation.h"

const char* CFoundation::SlotName()
{
	return "Foundation";
}
CFoundation::CFoundation()
{

}

CFoundation::~CFoundation()
{

}

bool CFoundation::CheckPushPrecondition( const CCard &_card )
{
	
	if( false == CSlot::CheckPushPrecondition( _card ) ) return false;
	
	if( _card.IsFaceDown() ) return false;
	
	if( 0 == this->GetCardsStored() && CCard::Ace == _card.GetValue() )
		return true;
	else
	{
		/* Get Card from top and put it back */
		CCard tmp(this->PeekCard());
	
		if	( 
				tmp.GetSuit() == _card.GetSuit() &&
				( 
					( tmp.GetValue() == CCard::Ace && _card.GetValue() == CCard::Two ) ||
					( tmp.GetValue() != CCard::Ace && 1 == tmp.CompareValue( _card ) )
				)
			)
			return true;
		else
			return false;
	}
}

#define SPACE_OPEN 2

void CFoundation::CalculateDrawingArea( int& _x, int&  _y, int& _width, int& _height )
{
	// max 13 open 

	_width = CARD_WIDTH;
	_height = 13 * SPACE_OPEN + CARD_HEIGHT;
	
}


void CFoundation::Draw(unsigned int _x, unsigned int _y, bool selected )
{
	ClearDrawingArea(_x, _y);

	if( cards_stored )
	{

		for( unsigned char i = 0; i < cards_stored; i++ )
		{
			cardstack[ i ].Draw( _x, _y + ( i * SPACE_OPEN ) );
		
		}
	}
	else
	{
		CCard::DrawPlaceHolder( _x, _y );
	}

	/* draw hand */

	if( selected )
	{
		CCard::DrawCursor( _x+20, _y+10 );
	}
}

bool CFoundation::IncreaseSelection()
{
	if( cards_stored && cards_selected == 0 )
	{
		cards_selected = 1;
		return true;
	}
	return false;
}
